<template>
  <div id="app">
    <h2>测试题</h2>
    <subject
      v-for="(obj, index) in list"
      :key="index"
      :arr="obj"
      :index="index"
      @yanzheng="yanFn"
    ></subject>
    <div>
      <flag
        v-for="(obj, index) in stats"
        :key="index"
        :stats="obj"
        :index="index"
      ></flag>
    </div>
  </div>
</template>

<script>
import subject from "./components/Subject";
import flag from "./components/Flag";
export default {
  components: {
    subject,
    flag,
  },

  data() {
    return {
      stats: ["undo", "undo", "undo", "undo", "undo"],
      relsum: "",
      list: [
        {
          f: `${parseInt(Math.random() * 10)}`,
          s: `${parseInt(Math.random() * 10)}`,
        },
        {
          f: `${parseInt(Math.random() * 10)}`,
          s: `${parseInt(Math.random() * 10)}`,
        },
        {
          f: `${parseInt(Math.random() * 10)}`,
          s: `${parseInt(Math.random() * 10)}`,
        },
        {
          f: `${parseInt(Math.random() * 10)}`,
          s: `${parseInt(Math.random() * 10)}`,
        },
        {
          f: `${parseInt(Math.random() * 10)}`,
          s: `${parseInt(Math.random() * 10)}`,
        },
      ],
    };
  },
  methods: {
    yanFn(index, sum) {
      this.relsum = Number(this.list[index].f) + Number(this.list[index].s);
      if (sum == this.relsum) {
        this.$set(this.stats, index, "yes");
        console.log(this.stats);
      } else {
        this.$set(this.stats, index, "no");
      }
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>